<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对象的增强与结构</title>
</head>
<body>
    <script>
        let height = 178;
        let weight = 60;

        const person = {
            // 键值对
            name: '叶尘仙',
            age: 20,
            height,
            weight, // es6语法
            // 方法修复：添加冒号或使用简写
            run: function () {
                console.log('run');
            },
            speak() { // 对象中方法的简写（ES6）
                console.log('speak');
            }
        };


        obj1 = {name:'shane'}
        obj2 = {
            run(){
                console.log('run');
              },
            }
            console.log(Object.assign(obj1,obj2));

            //对象的解构
            //什么是解构
            //快速从对象容器中提取成员的一种方式

            const obj3 = {
                name:'shane',
                age:20,
                sex:'man'
            }

            // var name = obj3.name;
            // var age = obj3.age;
            // var sex = obj3.sex;


            let {name,age,sex} = obj3;
            console.log(name,age,sex);

            //想要换名称，对象解构改属性方式用冒号
            let {name:n,age:a,sex:s} = obj3;
            console.log(n,a,s);
















        // 测试调用
        person.run();   // 输出: run
        person.speak(); // 输出: speak


















    </script>
</body>
</html>